package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.SalaryTaxActivity;
import com.lzx.iteam.bean.EventListData;
import com.lzx.iteam.bean.SalaryTaxBean;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * **********************************
 * User: zhangshuai
 * Date: 2017年 01月 09日
 * Time: 下午5:36
 *
 * @QQ : 1234567890
 * **********************************
 */
public class SalaryTaxAdapter extends BaseAdapter {

    private Context mContext;
    private int taxState;
    private ArrayList<SalaryTaxBean> mDatas;

    public SalaryTaxAdapter(Context mContext, int taxState, ArrayList<SalaryTaxBean> mDatas) {
        this.mContext = mContext;
        this.taxState = taxState;
        this.mDatas = mDatas;
    }

    public void bindData(int taxState){
        this.taxState = taxState;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        convertView = LayoutInflater.from(mContext).inflate(R.layout.salary_tax_item_layout,null);
        TextView title = (TextView) convertView.findViewById(R.id.tv_salary_tax_item_title);
        RelativeLayout taxLayout = (RelativeLayout) convertView.findViewById(R.id.rl_salary_tax_item_tax);
        TextView name = (TextView) convertView.findViewById(R.id.tv_salary_tax_item_name);
        TextView tax = (TextView) convertView.findViewById(R.id.tv_salary_tax_item_tax);
        ImageView check = (ImageView) convertView.findViewById(R.id.iv_salary_tax_item_check);

        SalaryTaxBean bean = mDatas.get(position);
        switch (bean.getType()){
            case 0:
                title.setText("国家规定比例");
                title.setVisibility(View.VISIBLE);
                taxLayout.setVisibility(View.GONE);
                break;
            case 1:
                name.setText("工资金额");
                tax.setText("比例");
                break;
            case 2:
                name.setText(bean.getName());
                tax.setText(bean.getTax() + "%");
                break;
            case 3:
                name.setText("工资扣税");
                tax.setVisibility(View.GONE);
                check.setVisibility(View.VISIBLE);
                if (taxState == 0){
                    check.setImageDrawable(mContext.getResources().getDrawable(R.drawable.iv_sa_check_normal));
                }else{
                    check.setImageDrawable(mContext.getResources().getDrawable(R.drawable.iv_sa_check_selected));
                }
                break;
            case 4:
                tax.setVisibility(View.GONE);
                check.setVisibility(View.VISIBLE);
                name.setText("工资不扣税");
                if (taxState == 0){
                    check.setImageDrawable(mContext.getResources().getDrawable(R.drawable.iv_sa_check_selected));
                }else{
                    check.setImageDrawable(mContext.getResources().getDrawable(R.drawable.iv_sa_check_normal));
                }
                break;
        }

        /*check.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((SalaryTaxActivity)mContext).setTaxState(mDatas.get(position));
            }
        });*/

        return convertView;
    }
}
